import 'package:flutter/material.dart';
import 'package:flutterlib/common/style/font_awesome4_icons.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/date_util.dart';
import 'package:flutterlib/common/utils/utils.dart';
import 'package:flutterlib/model/post/comment_bean.dart';
import 'package:flutterlib/widgets/bussiness/user_info_widget.dart';

class CommentListItem extends StatelessWidget {
  final CommentBean commentBean;

  final VoidCallback onUserPressed;

  final VoidCallback onCommentReplyPressed;

  CommentListItem(this.commentBean,
      {this.onUserPressed, this.onCommentReplyPressed})
      : super();

  @override
  Widget build(BuildContext context) {
    List<Widget> childrens = [];
    var children = commentBean.children ?? [];
    for(var comment in children){
      var children = Text.rich(
        TextSpan(
          children: [
            TextSpan(text: comment.author + ":", style: QuhuiConstant.minSubGray6Text),
            TextSpan(text: comment.content, style: QuhuiConstant.smallText),

          ]
        ),
      );
      childrens.add(children);
    }
    return Padding(
      padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
      child: Container(
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                UserInfoWidget(
                  onPressed: (){
                    NavigatorUtils.goUserHome(context, commentBean.userId);
                  },
                  width: 33,
                  height: 33,
                  image: commentBean.authorLogo,
                ),
                Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        children: [
                          Expanded(
                            child: Text(
                              commentBean.author,
                              style: QuhuiConstant.minSubGray6Text,
                            ),
                          ),
                          InkWell(
                            child:
                            Icon(AIcon.commenting,
                              size: 15.w,
                            ),
                            onTap: onCommentReplyPressed,
                          ),
                          Padding(
                            padding: const EdgeInsets.fromLTRB(8.0, 0, 5, 0),
                            child: Text(children.length.toString(), style: QuhuiConstant.minMinSubGray6Text,),
                          ),
                        ],
                      ),
                      Text(
                        MyDateUtil.getDiffTime(
                          commentBean.createTime,
                        ),
                        style: QuhuiConstant.minSubGray6Text,
                      ),
                      SizedBox(
                        height: 12,
                      ),
                      Text(commentBean.content, style: QuhuiConstant.smallText,),
                      children.length > 0 ? Container(
                        width: double.infinity,
                        padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                        decoration: BoxDecoration(
                          color: HexColor("#ECECEC"),



                          borderRadius: BorderRadius.all(Radius.circular(3)),
                        ),
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: childrens,
                        ),
                      ) : SizedBox(),

                    ],
                  ),
                ),

              ],
            ),
            Padding(
              padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
              child: Container(
                color: QuhuiColors.dividerColor,
                width: double.infinity,
                height: 0.3,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
